//
// Created by francklinson on 2021/5/20.
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// 同 丑数
class Solution {
public:
    int getKthMagicNumber(int k) {
        vector<int> container; // 结果容器
        container.push_back(1); // 1是第一个丑数
        int l3 = 0, l5 = 0, l7 = 0;
        int out2, out3, out5, temp;
        for (int i = 1; i < k; ++i) {
            out2 = container[l3] * 3;
            out3 = container[l5] * 5;
            out5 = container[l7] * 7;
            temp = min({out2, out3, out5});
            container.push_back(temp);
            if (temp == out2)++l3;
            if (temp == out3)++l5;
            if (temp == out5)++l7;
        }
        return container.back();
    }
};

int main() {
    Solution sol;
    cout << sol.getKthMagicNumber(5) << endl;
    return 0;
}
